package yns.springcloud.oakwood.guide.gateway;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

@Component
public class GuideRoute {

	@Bean
	public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
		return builder.routes()
				.route("route",r -> r.path("/spring-cloud-gateway").uri("https://www.baidu.com/"))
				.route("route1", r -> r.path("/consumer").uri("lb://spring-cloud-consumer-2"))
				.route("route2", r -> r.path("/producer").and().query("value").uri("lb://spring-cloud-consumer-2"))
				.route("route3",r -> r.path("/spring-cloud-gateway2")
						.filters(f -> f.redirect(HttpStatus.FOUND.value(), "https://www.baidu.com/")).uri("https://www.baidu.com/"))
						
				.build();
	}
	
}
